<template>
<h2>门店添加</h2>
    <table border="1">
        <tr>
            <td>门店名称</td>
            <td><input type="text" placeholder="请输入门店名称" v-model="info.Shop_Name"/></td>
        </tr>
         <tr>
            <td>分店名称</td>
            <td><input type="text" placeholder="请输入分店名称" v-model="info.Shop_BranchName"/></td>
        </tr>
         <tr>
            <td>门店地址</td>
            <td><input type="text" placeholder="请输入门店地址" v-model="info.Shop_Address"/></td>
        </tr>
         <tr>
            <td>门店电话</td>
            <td><input type="text" placeholder="请输入门店电话" v-model="info.Shop_Phone"/></td>
        </tr>
         <tr>
            <td>门店状态</td>
            <td>
                <input type="radio" :value="true" v-model="info.Phop_State"/>营业
                 <input type="radio" :value="false" v-model="info.Phop_State"/>未营业
            </td>
        </tr>
         <tr>
            <td>门店介绍</td>
            <td><input type="text" placeholder="请输入门店介绍" v-model="info.Shop_Info"/></td>
        </tr>
         <tr>
            <td>入店须知</td>
            <td><input type="text" placeholder="请输入入店须知" v-model="info.Shop_Notice"/></td>
        </tr>
         <tr>
            <td>交通通信</td>
            <td><input type="text" placeholder="请输入交通通信" v-model="info.Shop_Traffic"/></td>
        </tr>
        <tr>
            <td>门店图片</td>
            <td>
                <img style="width:70px;height:80px;" :src="info.Shop_Img"/>
                <input type="file" @change="FileUpLoads"/>
            </td>
        </tr>
         <tr>
            <td><input type="button" value="添加" @click="Add"/></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';

    const info=ref({
        Shop_Name: "",
        Shop_BranchName: "",
        Shop_Address: "",
        Shop_Phone: "",
        Phop_State: true,
        Shop_Info: "",
        Shop_Notice: "",
        Shop_Traffic: "",
        Shop_Img: ""
    });

    const Add=()=>{

        if(info.value.Shop_Name==""){
            alert('门店名称不能为空');
            return;
        }
        if(info.value.Shop_Address==""){
            alert('门店地址不能为空');
            return;
        }
        if(info.value.Shop_Phone==""){
            alert('门店电话不能为空');
            return;
        }
        if(info.value.Shop_Img){
            alert('门店图片不能为空');
        }
        axios.post("https://localhost:7153/api/Member/AddShop/AddShop",info.value)
        .then(res=>{
            if(res.data>0){
                alert('添加成功');
            }
            else if(res.data==-1){
                alert('已存在');
                return;
            }
            else{
                alert('添加失败');
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }
    

    //文件上传
    const FileUpLoads=(e:any)=>{
        //获取文件对象
        var file = e.target.files[0];

        //容器 表单数据
        var fd=new FormData();

        //将文件对象 保存到表单数据当中 append():保存数据的方法 键值对
        fd.append("Img",file);
        axios.post("https://localhost:7153/api/Files/FileUpload",fd)
        .then(res=>{
            // info.Shop_Img=res.data;
            console.log(res.data);
        })
        .catch(err=>{
            console.log(err);
        })
    }

    

</script>
